import { defineStore } from 'pinia';
import { ref } from 'vue';


export default   defineStore(
    'user',

    ()=>{
        
        const selectCategory=ref(null)
        const userInfo=ref(null)
        const time=ref(null)


   
        function setTime(val){
            time.value=val
        }
        function setUserInfo(val){
            userInfo.value=val
        }
        function getUserInfo(){
            return userInfo
        }
        function logout(){
             userInfo.value=null
        }
        // 存本地的个人信息两小时刷新一次（相当于缓存）
        return {
            expireTime:2*60*60*1000,
            time,
            selectCategory,
       
            userInfo,
            setTime,
       
            setUserInfo,
            getUserInfo,
            logout,
            setSelectCategory(val){
                selectCategory.value=val
            }
        }
    },
    {
		persist: {
			enabled: true,
			storage: localStorage,
			key: 'user'
		}
	}
)